home *** CD-ROM | disk | FTP | other *** search
- CMDLINE.DOC 7/8/84 Dave Williams [COMPUSERVE 74015,655]
-
-
- A. Listing 1 is a routine designed to enable the use of command line
- parameters by either compiled or interpreted BASIC programs. The
- routine is based on the following algorithm:
-
- (1) Determine if the program is compiled or not. (Line 1010)
-
- a. If the program using this routine also uses array variables,
- then line 1010 could use one of those variables instead of TEMP$().
-
-
- (2) Find the start of a Program Segment Prefix (PSP) that contains
- the desired command line. (Line 1020)
-
- a. The PSP for BASIC.COM (or BASICA.COM) is easy to find. Simply
- look at the vector address for INT 0. The segment address portion of
- this vector points to BASIC's PSP. (BASIC substitutes its own interrupt
- handler routines for this and several other interrupts, in addition to
- setting up new interrupts of its own. As a COM program, only one program
- segment address (such as that for INT 0) is needed.)
-
- b. The PSP for a compiled BASIC program, on the other hand, is
- pretty well hidden, and normally can't be found by looking at the
- interrupt vector addresses. (A compiled BASIC program is usually a EXE
- program and typically use several different program segment addresses.)
- Instead a method such as that given by W.M. Sparks in PC World (Nov 83,
- p.260) must be used. His program, known as BASPARM.BAS (or
- BASPARAM.BAS) is widely available.
-
- c. The routine given here makes use of the fact that DOS places
- a copy of the command line in the PSP for COMMAND.COM when any EXE or COM
- program is called. This PSP can be found by simply looking at the vector
- address for INT 21.
-
- (3) Read in the command line from the command line buffer in the PSP.
- (Lines 1030-1050)
-
- a. The length of the command line is given by the byte at hex
- offset 80 in the PSP, while the command line itself starts at hex offset
- 81.
-
- b. Line 1040 of the routine is not needed for proper operation.
- It is included only to provide for a fast exit if the command line is
- empty.
-
- (4) Delete any leading spaces. (Line 1070)
-
- (5) If the program is not compiled, then delete the name of the
- called program. (Lines 1080-1090)
-
- a. When a COM or EXE program is called, DOS will automatically
- delete the program filespec from the command line before it is placed
- in the PSP. In the case of interpreted BASIC, this is BASIC.COM (or
- BASICA.COM). The filespec of the program to be run by BASIC will remain
- as part of the command line, and must be removed.
-
- b. It should be noted that DOS filter and redirection commands
- (i.e., those using <,>, or |) will not appear in the command line when
- using DOS 2.0 and above.
-
- (6) Strip off leading and trailing spaces. (Lines 1110-1120)
-
-
- B. Listing 2 is a routine that may be used to investigate the PC's
- memory. It will first display all of the the interrupt vectors (segment
- address first). It will then display the first 256 bytes of any selected
- area of memory. The 256 byte range may be varied by changing the value
- of N in line 100.
-
-
-
- LISTING 1:
-
- 10 'CMDLINE.BAS Version 2.01 Dave Williams [COMPUSERVE 74015,655]
- 20 'This routine is designed to enable the use of command line parameters by either compiled or interpreted BASIC.
- 1000 CLS:KEY OFF:DEFINT A-Z
- 1010 DIM TEMP$(1):IF (VARPTR(TEMP$(1))-VARPTR(TEMP$(0)))=4 THEN COMPILED=-1
- 1020 DEF SEG=0:PSP!=PEEK(134)+256*PEEK(135) 'find PSP for COMMAND.COM
- 1030 DEF SEG=PSP!+8:TEMP=PEEK(0) 'find length of command line
- 1040 IF TEMP=0 THEN CMDLINE$="":GOTO 1130 'no command line parameters exist
- 1050 CMDLINE$=SPACE$(TEMP):FOR I=1 TO TEMP:MID$(CMDLINE$,I,1)=CHR$(PEEK(I)):NEXT 'read in command line
- 1060 DEF SEG
- 1070 WHILE LEFT$(CMDLINE$,1)=CHR$(32):CMDLINE$=RIGHT$(CMDLINE$,LEN(CMDLINE$)-1):WEND 'strip off leading spaces
- 1080 IF COMPILED THEN 1100 ELSE TEMP=1
- 1090 TEMP=INSTR(CMDLINE$,CHR$(32)):CMDLINE$=MID$(CMDLINE$,TEMP+1) 'strip off program name (if any)
- 1100 IF TEMP=0 OR CMDLINE$=SPACE$(LEN(CMDLINE$)) THEN CMDLINE$="":GOTO 1130 'no command line parameters exist
- 1110 WHILE RIGHT$(CMDLINE$,1)=CHR$(32):CMDLINE$=LEFT$(CMDLINE$,LEN(CMDLINE$)-1):WEND 'strip off trailing spaces
- 1120 WHILE LEFT$(CMDLINE$,1)=CHR$(32):CMDLINE$=RIGHT$(CMDLINE$,LEN(CMDLINE$)-1):WEND 'strip off leading spaces
- 1130 PRINT "Command line = ";CMDLINE$;CHR$(10);"Length =";LEN(CMDLINE$)
- 1140 END
-
-
-
- LISTING 2:
-
- 10 'LOOK.BAS Version 3.27 7/5/84 Dave Williams [74015,655]
- 20 'This program will display all interrupt vector addresses and any 256-byte section of memory.
- 30 'Change the value of N in line 100 to change the amount of memory displayed.
- 100 KEY OFF:CLS:DEFINT A-N:N=255
- 110 DEF FNTST(X)=PEEK(X)+256*PEEK(X+1)
- 120 DEF FNTST1$(X)=RIGHT$("0000"+HEX$(X),4)
- 130 DEF FNTST2$(X)=RIGHT$("0000",5-LEN(STR$(X)))+RIGHT$(STR$(X),LEN(STR$(X))-1)
- 140 DEF FNTST3$(X)=RIGHT$("0000"+HEX$(X),2)
- 150 CLS:DEF SEG=0
- 160 A$="INT"+SPACE$(4)+"VECTOR"+SPACE$(7)+"ADDRESS"+CHR$(10):PRINT A$
- 170 FOR I=0 TO 1023 STEP 4
- 180 A$=FNTST3$(I\4)+SPACE$(4)+FNTST1$(FNTST(I+2))+CHR$(58)+FNTST1$(FNTST(I))+SPACE$(6)+FNTST2$(I):PRINT A$
- 190 NEXT
- 200 PRINT:INPUT "List interrupts again? [Default=N] ",T$:T$=LEFT$(T$,1):IF T$="Y" OR T$="y" THEN 150
- 210 PRINT CHR$(10);"[Press <ENTER> to exit]";CHR$(10);"Segment address (in hex) = ";CHR$(9);CHR$(9);"[Add </> to repeat]";
- 220 LOCATE ,28:INPUT "",P$:IF P$="" THEN 350
- 230 D=INSTR(P$,CHR$(47)):IF D THEN A$=CHR$(47):P$=LEFT$(P$,D-1) ELSE A$=""
- 240 P=VAL("&H"+P$):P=P-(P<0)*65536!:P$=FNTST1$(P)
- 250 PRINT "Offset address (in hex) = ";CHR$(9);CHR$(9);"[Default=0000] [Enter </> to exit]";
- 260 LOCATE ,28:INPUT "",O$
- 270 D=INSTR(O$,CHR$(47)):IF D THEN O$=LEFT$(O$,D-1):IF O$="" THEN 210
- 280 IF O$="" THEN O=0 ELSE O=VAL("&H"+O$):O=O-(O<0)*65536!
- 290 CLS:DEF SEG=P
- 300 FOR I=0 TO N STEP 16:T$=P$+CHR$(58)+FNTST1$(I+O)+SPACE$(4):U$="":V$=SPACE$(13):FOR J=I TO 15+I
- 310 K=PEEK(O+J):U$=U$+RIGHT$("00"+HEX$(K),2)+CHR$(32)
- 320 IF K<32 OR K>128 THEN V$=V$+SPACE$(3) ELSE V$=V$+CHR$(K)+SPACE$(2)
- 330 NEXT:PRINT T$;U$;CHR$(10);V$:PRINT:NEXT:PRINT
- 340 IF A$<>"" THEN 250 ELSE 210
- 350 PRINT:INPUT "List interrupts again? [Default=N] ",T$:T$=LEFT$(T$,1):IF T$="Y" OR T$="y" THEN 150
- 360 CLS:DEF SEG
- 370 END
- ault=N] ",T$:T$=LEFT$(T$,1):IF T$="Y" OR T$="y" THEN 150
- 360 CLS:DEF SEG
- 370 END
-